<template>
  <bui-page-layout ref="pageLayout" :is-z-paging="true">
    <template v-slot:header>
      <view class="friend-info" v-if="friendTotal > 0">
        <text class="t">共{{friendTotal}}位好友</text>
      </view>
    </template>
    <z-paging :auto-show-back-to-top="true" empty-view-text="暂无好友" back-to-top-bottom="220rpx" ref="zpaging" safe-area-inset-bottom v-model="dataList" :show-loading-more-when-reload="true" :show-loading-more-no-more-view="getList.length > 9" :auto-clean-list-when-reload="true" @query="getList" :fixed="false" :empty-view-fixed="false">
      <view class="friend-list">
        <view class="friend-item" v-for="(item,index) in dataList" :key="index">
          <image :src="item.headimgurl || '/static/image/icon-user-avatar.png'" class="avatar" />
          <view class="user-info">
            <view class="name"><text class="n">{{ item.nickname }}</text></view>
            <view class="vip-icon">
              <image :src="item.levelIcon" class="icon" />
            </view>
          </view>
          <view class="amount">
            <text class="p add">{{item.commission?'+':''}}{{ item.commission }}</text>
            <text class="t">店铺收益</text>
          </view>
        </view>
      </view>
    </z-paging>
  </bui-page-layout>
</template>
<script setup>
import { ref, reactive } from "vue";

var dataList = ref([]);
var zpaging = ref(null);
var friendTotal = ref(0);
const getList = (pageNum, pageSize) => {
  var options = {
    limit: pageSize,
    page: pageNum,
  };
  uni.$request
    .service({
      url: "/m/invite/record",
      method: "POST",
      data: options,
      isLoading: true,
    })
    .then((res) => {
      friendTotal.value = res.total;
      zpaging.value.completeByTotal(res.list || [], res.total);
    })
    .catch((error) => {
      uni.$u.toast(error.message);
    });
};
</script>
<style lang="scss">
page {
  background-color: #f6f6f8;
}
.friend-info {
  padding: 20rpx 30rpx;
  .t {
    font-size: 28rpx;
    color: #9eb0c5;
  }
}
.friend-list {
  background-color: #fff;
  .friend-item {
    display: flex;
    align-items: center;
    position: relative;
    padding: 20rpx 20rpx;
    &::after {
      content: "";
      display: block;
      position: absolute;
      left: 20rpx;
      right: 20rpx;
      height: 2rpx;
      background-color: #f3f3f3;
      top: 0;
    }
    .avatar {
      width: 100rpx;
      height: 100rpx;
      border-radius: 100rpx;
    }
    .user-info {
      flex: 1;

      padding-left: 20rpx;
      .name {
        padding-top: 10rpx;
        .n {
          font-size: 28rpx;
          font-weight: 600;
          color: #232f3f;
          position: relative;
        }
      }
      .vip-icon {
        padding-top: 10rpx;
        .icon {
          width: 140rpx;
          height: 40rpx;
        }
      }
    }
    .amount {
      display: flex;
      flex-direction: column;
      .p {
        font-size: 32rpx;
        display: flex;
        justify-content: flex-end;
      }
      .p.add {
        color: #fe9900;
      }
      .p.sub {
        color: #232f3f;
      }
      .t {
        font-size: 24rpx;
        color: #9eb0c5;
        text-align: right;
      }
    }
  }
  .friend-item:first-child {
    &::after {
      display: none;
    }
  }
}
</style>
